<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
* Google Analytics
*
* Inserts google analytics tracking code into view
* If a tracking code is passed in, then it will use that uacct info
* Otherwise, it will use the value defined in the google.php config file
* If both values do not exist, nothing will be inserted.
*
* @access    public
* @param    string
* @return    string
*/
function google_analytics($uacct = '')
{
    
    $CI =& get_instance();
    if( $uacct != '' || $CI->config->slash_item('google_uacct') != '' ){

    	$google_analytics_code = '
                <script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
				</script>
				<script type="text/javascript">
                _uacct = "';

        if($CI->config->slash_item('google_uacct') != ''){
            
            // Found config setting
            $google_analytics_code .= $CI->config->item('google_uacct');
            
        }
        
        // In the event that both the google_uacct variable is set, AND we find that the $uacct
        // Variable is passed in, the return variable $google_analytics_code will be overwritten
        // with the $uacct variable taken priority.
        
        if($uacct != ''){
            
            // Found $uacct variable data
            $google_analytics_code .= $uacct;
            
        }
        
        $google_analytics_code .= '";
                urchinTracker();
                </script>';

            return $google_analytics_code;
    
    }
    
}

?>